package com.zs.blog.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Title: MybtisPlusConfig
 * @Author zs
 * @Package com.zs.blog.config
 * @Date 2024/10/20 17:14
 * @description: mybatis-plus配置类
 */
@Configuration
public class MybatisPlusConfig {

    /**
     * 添加分页插件
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        // Mybatis-plus拦截器
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // Mybatis-plus内置分页拦截器
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
        // 设置分页拦截器属性 不同数据库，分页的语法不同 方言设置
        paginationInnerInterceptor.setDbType(DbType.MYSQL);
        // 将分页拦截器添加到mp拦截器中
        interceptor.addInnerInterceptor(paginationInnerInterceptor);
        return interceptor;
    }
}
